// PersistentObjectManager.cpp: implementation of the PersistentObjectManager class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PersistentObjectManager.h"
#include "PersistentObject.h"
#include "UeObjectId.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

PersistentObjectManager::PersistentObjectManager()
{

}

PersistentObjectManager::~PersistentObjectManager()
{

}
PersistentObjectManager& GetCurManager()
{
	static PersistentObjectManager Manager;
	return Manager;
}


void PersistentObjectManager::Add(PersistentObject* pObj)
{
	ASSERT(pObj);
	if(pObj->Id().IsNull())
	{
		pObj->Id( UeObjectId( 0, this->GenerateIndex() ) );
	}
	else if(IsExist(pObj->Id()))
	{
		return;		
	}
	
	ManagerTemplate<UeObjectId, PersistentObject>::Add(pObj->Id(), pObj);
}

PersistentObject* PersistentObjectManager::Get(const UeObjectId& id)
{
	ASSERT(!id.IsNull());

	return this->GetManaged(id);
}
